﻿using System;
using System.Linq;
using System.Web.UI;
using MyFavorites.Model;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            string UserName = Request.Form["txtUserName"];
            string Password = Request.Form["txtPassword"];
            using (Entities entitie = new Entities())
            {
                C_User user = entitie.C_User.SingleOrDefault(u => u.UserName == UserName && u.RecordStatus=="Active");
                if (user != null)
                {
                    C_UserInfo userInfo = user.C_UserInfo.FirstOrDefault();
                    PassportInfoEntity pie = new PassportInfoEntity();
                    pie.UserID = user.UserID;
                    pie.UserInfoID = userInfo.UserInfoID;
                    pie.UserName = user.UserName;
                    pie.Language = userInfo.Language;
                    pie.NickName = userInfo.NickName;
                    pie.PhoneNo = userInfo.PhoneNo;
                    pie.Email = userInfo.Email;
                    pie.Birthday = userInfo.Birthday.GetValueOrDefault();
                    Passport<PassportInfoEntity>.SignIn(UserName, pie, 10);
                    Response.Redirect("~/" + UserName);
                }
            }
        }
    }
}